﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ISay_TelaLogin
{
    public partial class Form1 : Form
    {
        SqlConnection conexao;

        public Form1()
        {
            InitializeComponent();
        }

        private void lbl_cliqueAqui_Click(object sender, EventArgs e)
        {
            FormCadastro novoForm = new FormCadastro();
            novoForm.ShowDialog();            
        }

        private void lbl_cadastro_Click(object sender, EventArgs e)
        {
            lbl_cliqueAqui_Click(sender, e);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string connectionString = Properties.Settings.Default.iSayConnectionString;
            conexao = new SqlConnection(connectionString);
            conexao.Open();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            SqlCommand comandosql = new SqlCommand("SELECT email, senha FROM Usuario WHERE email='" + comboBox1.Text+"'", conexao);
            SqlDataReader DataReader = comandosql.ExecuteReader();

            if (DataReader.Read())
            {
                if (DataReader["senha"].ToString() == textBox1.Text)
                {
                    conexao.Close();
                    DataReader.Close();
                    telaConversa novatela = new telaConversa(comboBox1.Text);
                    novatela.Show();
                }
                else
                {
                    MessageBox.Show("Senha digitada incorretamente!");
                    DataReader.Close();
                }
            }
            else
            {
                MessageBox.Show(" O email digitado não corresponde a nenhum usuário em nosso bando de dados\n"+
                                " Verifique se foi digitado corretamente.");
                DataReader.Close();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            button1_Click(sender, e);
        }

        private void button1_MouseEnter(object sender, EventArgs e)
        {
            button1.ForeColor = Color.Black;
        }

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            button1.ForeColor = Color.White;
        }
    }
}
